<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML> 
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>评论管理</title>
	<!-- 引入css样式文件 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div id="wrapper">
  <!-- 导航栏部分 -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation"
		 style="margin-bottom: 0">
	<div class="navbar-header">
		<a class="navbar-brand" href="<%=basePath%>user"><i class="fa fa-home fa-fw"></i>干饭系统</a>
    </div>
	<ul class="nav navbar-top-links navbar-right">
		<!-- 用户信息和系统设置 start -->
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
				<i class="fa fa-user fa-fw"></i>
				<i class="fa fa-caret-down"></i>
			</a>
			<ul class="dropdown-menu dropdown-user">
				<li><a href="#"><i class="fa fa-user fa-fw"></i>
				               用户：${sessionScope.USER.userName}
				    </a>
				</li>
				<li><a href="#"><i class="fa fa-gear fa-fw"></i> 系统设置</a></li>
				<li class="divider"></li>
				<li>
					<a href="${pageContext.request.contextPath }/logout">
					<i class="fa fa-sign-out fa-fw"></i>退出登录
					</a>
				</li>
			</ul> 
		</li>
		<!-- 用户信息和系统设置结束 -->
    </ul>
	<!-- 左侧显示列表部分 start-->
	<div class="navbar-default sidebar" role="navigation">
		<div class="sidebar-nav navbar-collapse">
			<ul class="nav" id="side-menu">
				<li>
					<a href="${pageContext.request.contextPath }/user" class="active">
						<i class="fa fa-address-card fa-fw" ></i> 用户管理
					</a>
				</li>
				<!-- -->
				<li>
					<a href="${pageContext.request.contextPath }/restaurant" class="active">
						<i class="fa fa-cutlery fa-fw"></i> 餐厅管理
					</a>
				</li>
				<li>
					<a href="${pageContext.request.contextPath }/table" class="active">
						<i class="fa fa-wheelchair-alt fa-fw"></i> 餐桌管理
					</a>
				</li>
				<li>
					<a href="${pageContext.request.contextPath }/dish" class="active">
						<i class="fa fa-spoon fa-fw"></i> 菜品管理
					</a>
				</li>
				<li>
					<a href="${pageContext.request.contextPath }/coupon" class="active">
						<i class="fa fa-percent fa-fw"></i> 折扣管理
					</a>
				</li>
				<li>
					<a href="${pageContext.request.contextPath }/ingredientstock" class="active">
						<i class="fa fa-leaf fa-fw"></i> 食材管理
					</a>
				</li>
				<li>
					<a href="${pageContext.request.contextPath }/order" class="active">
						<i class="fa fa-cart-arrow-down fa-fw"></i> 订单管理
					</a>
				</li>
				<li>
					<a href="${pageContext.request.contextPath }/reservation" class="active">
						<i class="fa fa-bell fa-fw"></i> 预定管理
					</a>
				</li>
				<li>
					<a href="${pageContext.request.contextPath }/review" class="active">
						<i class="fa fa-comment fa-fw"></i> 评论管理
					</a>
				</li>
				<li>
					<a href="${pageContext.request.contextPath }/usercoupon" class="active">
						<i class="fa fa-ticket fa-fw"></i> 优惠券管理
					</a>
				</li>
			</ul>
		</div>
	</div>
	<!-- 左侧显示列表部分 end--> 
  </nav>
    <!-- 列表查询部分  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header"><i class="fa fa-comment fa-fw"></i>评论管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->
		<div class="panel panel-default">
			<div class="panel-body">
				<form class="form-inline" method="get" 
				      action="${pageContext.request.contextPath }/review">
					<div class="form-group">
						<label for="reviewId">编号</label>
						<input type="text" class="form-control" id="reviewId"
						                   value="${reviewId }" name="reviewId" />
					</div>
					<div class="form-group">
						<label for="userName">评论所属用户名称</label>
						<input type="text" class="form-control" id="userName" 
						                   value="${not empty reverseUserMap[userName] ? reverseUserMap[userName] : ''}" name="userName" />
					</div>
					<button type="submit" class="btn btn-primary" >查询</button>
				</form>
			</div>
		</div>
		<a href="#" class="btn btn-primary" data-toggle="modal" 
		           data-target="#newUserDialog" onclick="clearUser()">新建</a>
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">评论信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
						<tr>
							<th>评论编号</th>
							<th>评论用户</th>
							<th>评论餐厅</th>
							<th>用户打分</th>
							<th>评论内容</th>
							<th>评论时间</th>
							<th>操作</th>
						</tr>
						</thead>
						<tbody>
						<c:forEach items="${page.rows}" var="row">
							<c:if test="${not empty restaurantMap[row.restId]}">
							<tr>
								<td>${row.reviewId}</td>
								<td>${userMap[row.userId]}</td>
								<td>${restaurantMap[row.restId]}</td>
								<td>${row.reviewScore}</td>
								<td>${row.reviewContext}</td>
								<td>${row.reviewDate}</td>
								<td><center>
									<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#userEditDialog" onclick= "editReview(${row.reviewId})">修改</a>
									<a href="#" class="btn btn-danger btn-xs" onclick="deleteReview(${row.reviewId})">删除</a>
								</td>
							</tr>
						</c:if>
						</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<ujn:page url="${pageContext.request.contextPath }/review" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>
	<!-- 列表查询部分  end-->
</div>
<!-- 创建模态框 -->
<div class="modal fade" id="newUserDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新建用户信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="new_user_form">
					<div class="form-group">
						<label for="new_userId" class="col-sm-2 control-label">
						    评论用户
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_userId" placeholder="评论用户" name="userId" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_restId" class="col-sm-2 control-label">评论餐厅</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_restId" placeholder="评论餐厅" name="restId" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_reviewContext" class="col-sm-2 control-label">评论内容</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_reviewContext" placeholder="评论内容" name="reviewContext" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_reviewDate" class="col-sm-2 control-label">评论时间</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_reviewDate" placeholder="评论时间" name="reviewDate" />
						</div>
					</div>
                    <div class="form-group">
						<label for="new_reviewScore" class="col-sm-2 control-label">用户打分</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_reviewScore" placeholder="用户打分" name="reviewScore" />
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="createReview()">创建用户</button>
			</div>
		</div>
	</div>
</div>
<!-- 修改模态框 -->
<div class="modal fade" id="userEditDialog" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改用户信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_user_form">
					<input type="hidden" id="edit_reviewId" name="reviewId"/>
					<div class="form-group">
						<label for="edit_userId" class="col-sm-2 control-label">
						    评论用户
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_userId" placeholder="评论用户" name="userId" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_restId" class="col-sm-2 control-label">评论餐厅</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_restId" placeholder="评论餐厅" name="restId" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_reviewContext" class="col-sm-2 control-label">评论内容</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_reviewContext" placeholder="评论内容" name="reviewContext" />
						</div>
					</div>
					<div class="form-group">
						<label for="edit_reviewDate" class="col-sm-2 control-label">评论时间</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_reviewDate" placeholder="评论时间" name="reviewDate" />
						</div>
					</div>
                    <div class="form-group">
						<label for="edit_reviewScore" class="col-sm-2 control-label">用户打分</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_reviewScore" placeholder="用户打分" name="reviewScore" />
						</div>
					</div>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="updateReview()">保存修改</button>
			</div>
		</div>
	</div>
</div>
<!-- 引入js文件 -->
<!-- jQuery -->
<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="<%=basePath%>js/metisMenu.min.js"></script>
<!-- DataTables JavaScript -->
<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="<%=basePath%>js/sb-admin-2.js"></script>
<!-- 编写js代码 -->
<script type="text/javascript">
//清空新建窗口中的数据
	function clearReview() {
	    $("#new_userId").val("");
	    $("#new_restId").val("")
	    $("#new_reviewCondition").val("")
	    $("#new_reviewDate").val("")
	    $("#new_reviewScore").val("")
	}
	// 创建
	function createReview() {
	$.post("<%=basePath%>review",
	$("#new_user_form").serialize(),function(data){
	        if(data =="OK"){
	            alert("用户创建成功！");
	            window.location.reload();
	        }else{
	            alert("用户创建失败！");
	            window.location.reload();
	        }
	    });
	}
	// 通过id获取修改的用户信息
	function editReview(id) {
	    $.ajax({
	        type:"GET",
	        url:"<%=basePath%>review/" + id,
	        success:function(data) {
				$("#edit_reviewId").val(data.reviewId);
	            $("#edit_userId").val(data.userId);
	            $("#edit_restId").val(data.restId);
	            $("#edit_userName").val(data.userName);
	            $("#edit_reviewCondition").val(data.reviewCondition);
	            $("#edit_reviewScore").val(data.reviewScore);
	        }
	    });
	}
    // 执行修改操作
	function updateReview() {
		var reviewId = $("#edit_reviewId").val();
	    var userId = $("#edit_userId").val();
	    var restId = $("#edit_restId").val();
        var userName = $("#edit_userName").val();
        var reviewCondition = $("#edit_reviewCondition").val();
        var reviewScore = $("#edit_reviewScore").val();
	    $.ajax({
           url: '<%=basePath%>review/' + reviewId,
           type: 'PUT',
           data : JSON.stringify({
			   reviewId : reviewId,
				userId : userId,
				restId  : restId ,
				userName : userName,
				reviewCondition : reviewCondition,
				reviewScore : reviewScore
			}),
	       contentType : "application/json;charset=UTF-8",
           success: function(data) {
                    if(data =="OK"){
         				window.location.reload();
         			}else{
         				window.location.reload();
         			}
           }
       });
	}
	// 删除
	function deleteReview(id) {
	    if(confirm('确实要删除吗?')) {
	    $.ajax({   url: '<%=basePath%>review/'+id,
                   type: 'DELETE',
                   success: function(data) {
                            if(data =="OK"){
                 				window.location.reload();
                 			}else{
                 				window.location.reload();
                 			}
                   }
        });
	    }
	}
</script>
</body>
</html>